/**
 * 
 * @Description : 加载页面：区域，景区类型，景区信息公共JS
 * @return void
 * @author :likun
 * @date : 2016年7月15日
 */
srvMap.add('querySourceCityList','','front/sh/localAnalysis!execute?uid=querySourceCityList');
srvMap.add('queryCityList', 'queryCityList', 'front/sh/analysis!execute?uid=queryCityList');//初始化区域
srvMap.add('queryRegionTypleList','','front/sh/analysis!execute?uid=queryRegionTypleList');//初始化景区类型
srvMap.add('queryRegionList','','front/sh/analysis!execute?uid=queryRegionList');//初始化景区
Util.loadUpInfo = {
		loadDescCityList : function() {
			Util.ajax.postJsonSync(srvMap.get('querySourceCityList'), '', function(json,
					status) {
				if (status) {
					var cityList = json.object.cityList;
					var cityHtml = '';
					var defaultCityHtml='';
					for (var i = 0; i < cityList.length; i++) {
						cityHtml += '<li onclick="Util.loadUpInfo.chooseDescLiItem(this);" d_value="' + cityList[i].city_id + '">'
								+ cityList[i].city_name + '</li>';
						
						if(cityList.length==1){
							defaultCityHtml+='<li onclick="Util.loadUpInfo.chooseDescLiItem(this);" d_value="' + cityList[i].city_id + '">'
							+ cityList[i].city_name + '</li>';
							$('#citySelectSpan2').html(defaultCityHtml);
						}
						
						if(cityList[i].city_id==''){
							defaultCityHtml+='<li onclick="Util.loadUpInfo.chooseDescLiItem(this);" d_value="' + cityList[i].city_id + '">'
							+ cityList[i].city_name + '</li>';
							$('#citySelectSpan2').html(defaultCityHtml);
						}
					}
					$('#cityListInfo2').html(cityHtml);
				} else {
					alert('初始化地市列表出错！');
				}
			});

		},
		loadSourceCityList : function() {
			Util.ajax.postJsonSync(srvMap.get('querySourceCityList'), '', function(json,
					status) {
				if (status) {
					var cityList = json.object.cityList;
					var cityHtml = '';
					var cityHtml2 = '';
					var defaultCityHtml='';
					var defaultCityHtml2='';
					for (var i = 0; i < cityList.length; i++) {
						cityHtml += '<li onclick="Util.loadUpInfo.chooseSourceLiItem(this);" d_value="' + cityList[i].city_id + '">'
								+ cityList[i].city_name + '</li>';
						
						if(cityList.length==1){
							defaultCityHtml+='<li onclick="Util.loadUpInfo.chooseSourceLiItem(this);" d_value="' + cityList[i].city_id + '">'
							+ cityList[i].city_name + '</li>';
							$('#citySelectSpan').html(defaultCityHtml);
						}
						
						if(cityList[i].city_id==''){
							defaultCityHtml+='<li onclick="Util.loadUpInfo.chooseSourceLiItem(this);" d_value="' + cityList[i].city_id + '">'
							+ cityList[i].city_name + '</li>';
							$('#citySelectSpan').html(defaultCityHtml);
						}
					}
					$('#cityListInfo').html(cityHtml);
				} else {
					alert('初始化地市列表出错！');
				}
			});

		},
	loadCityList : function() {
		Util.ajax.postJsonSync(srvMap.get('queryCityList'), '', function(json,
				status) {
			if (status) {
				var cityList = json.object.cityList;
				var cityHtml = '';
				var defaultCityHtml='';
				for (var i = 0; i < cityList.length; i++) {
					cityHtml += '<li onclick="Util.loadUpInfo.chooseLiItem(this);" d_value="' + cityList[i].city_id + '">'
							+ cityList[i].city_name + '</li>';
					
					if(cityList.length==1){
						defaultCityHtml+='<li onclick="Util.loadUpInfo.chooseLiItem(this);" d_value="' + cityList[i].city_id + '">'
						+ cityList[i].city_name + '</li>';
						$('#citySelectSpan').html(defaultCityHtml);
					}
					
					if(cityList[i].city_id==''){
						defaultCityHtml+='<li onclick="Util.loadUpInfo.chooseLiItem(this);" d_value="' + cityList[i].city_id + '">'
						+ cityList[i].city_name + '</li>';
						$('#citySelectSpan').html(defaultCityHtml);
					}
				}
				$('#cityListInfo').html(cityHtml);
			} else {
				alert('初始化地市列表出错！');
			}
		});

	},
	loadRegionTypleList:function(){
		Util.ajax.postJsonSync(srvMap.get('queryRegionTypleList'),'',function(json,status){
			if(status){
				var regionTypeList = json.object.regionTypeList;
				var regionTypeHtml = '';
				var defaultRegionTypeHtml='';
				for (var i = 0; i < regionTypeList.length; i++) {
					if(regionTypeList[i].region_type==''){
						defaultRegionTypeHtml+='<li onclick="Util.loadUpInfo.chooseLiItemForRegionType(this);" d_value="' + regionTypeList[i].region_type + '">' + regionTypeList[i].region_type_name + '</li>';
						$('#regionTypleSpan').html(defaultRegionTypeHtml);
					}
					regionTypeHtml += '<li onclick="Util.loadUpInfo.chooseLiItemForRegionType(this);" d_value="' + regionTypeList[i].region_type + '">' + regionTypeList[i].region_type_name + '</li>';
				}
				$('#regionTypleInfo').html(regionTypeHtml);
			}
			else{
				 alert('初始化景区类型列表出错！');
			}
		});
	},
	loadRegionList:function(){
		var cityId = $('#citySelect').find('li').attr("d_value");
		var regionType = $('#regionTypleSelect').find('li').attr("d_value");
		if (cityId==null||typeof(cityId) == 'undefined') {
			cityId="";
		}
		if (regionType==null||typeof(regionType) == 'undefined') {
			regionType="";
		}
		var par = "&cityId="+cityId+"&regionType="+regionType;
		Util.ajax.postJsonSync(srvMap.get('queryRegionList'),par,function(json,status){
			if(status){
				var regionList = json.object.regionList;
				allRegionList=regionList;
				$.divselect("#divselect","#inputselect",allRegionList);
				var regionHtml = '';
				for (var i = 0; i < regionList.length; i++) {
					regionHtml += '<option  value="' + regionList[i].region_id + '">' + regionList[i].region_name + '</option>';
				}
				$('#selectId').html(regionHtml);
			}else{
				 alert('初始化景区列表错误');   
			}
		
		});
		
		
		
	},
	onClickForCityShow:function(){
		$('#cityListInfo').css('z-index','999');
		$('#citySelect').click(function(){
			//$('#divselectInput').val('搜索景区，请输入名称');
			$('#cityListInfo').toggle();
		});
	},
	onClickForCityShow2:function(){
		$('#cityListInfo2').css('z-index','999');
		$('#citySelect2').click(function(){
			//$('#divselectInput').val('搜索景区，请输入名称');
			$('#cityListInfo2').toggle();
		});
	},
	onClickForRegionTypleShow:function(){
		$('#regionTypleInfo').css('z-index','999');
		$('#regionTypleSelect').click(function(){
			$('#divselectInput').val('搜索景区，请输入名称');
			$('#regionTypleInfo').toggle();
		});
	},
	chooseSourceLiItem:function(thisObj){
//		   console.info(thisObj);
			var obj=$(thisObj).clone()[0];
		   $('#citySelectSpan').html(obj);
		   $('#cityListInfo').hide();
		   //Util.loadUpInfo.loadRegionList(); 
		   },
		   chooseDescLiItem:function(thisObj){
//			   console.info(thisObj);
				var obj=$(thisObj).clone()[0];
			   $('#citySelectSpan2').html(obj);
			   $('#cityListInfo2').hide();
			   //Util.loadUpInfo.loadRegionList(); 
			   },
   chooseLiItem:function(thisObj){
//	   console.info(thisObj);
		var obj=$(thisObj).clone()[0];
	   $('#citySelectSpan').html(obj);
	   $('#cityListInfo').hide();
	   Util.loadUpInfo.loadRegionList(); 
	   },
   chooseLiItemForRegionType:function(thisObj){
			var obj=$(thisObj).clone()[0];
		   $('#regionTypleSpan').html(obj);
		  $('#regionTypleInfo').hide();
		  Util.loadUpInfo.loadRegionList();   
		   },
   initSearch:function(){

		$("#divselectInput").keyup(function(){
			var searchValue = $("#divselectInput").val();
			var resultRegionList=[];
			if (searchValue==null||searchValue==""||typeof(searchValue)=="undefined") {
				resultRegionList=allRegionList;
			}else {
				for (var i = 0; i < allRegionList.length; i++) {
					if (allRegionList[i].region_name.indexOf(searchValue)>-1) {
						resultRegionList.push(allRegionList[i]);
					}
				}
			}
			$.divselect("#divselect","#inputselect",resultRegionList);
		});

	   
	   
   },
   onclickOnbodyForCity:function(){
	   $("*").click(function (event) {
		    if ($(this).hasClass("hasCitySelect")){
			               event.stopPropagation(); //阻止事件冒泡  
			               }
		    else{
		                  $("#cityListInfo").hide();
		   }   
		   
		});
   },
   onclickOnbodyForCity2:function(){
	   $("*").click(function (event) {
		    if ($(this).hasClass("hasCitySelect2")){
			               event.stopPropagation(); //阻止事件冒泡  
			               }
		    else{
		                  $("#cityListInfo2").hide();
		   }   
		   
		});
   },
   onclickOnbodyForRegionTyple:function(){
	   $("*").click(function (event) {
			    if ($(this).hasClass("hasRegionTypleSelect")){
				               event.stopPropagation(); //阻止事件冒泡  
				               }else{
					                   $("#regionTypleInfo").hide();
				   }
				   
		});
   },
   onclickOnbodyForRegionList:function(){
	   $("*").click(function (event) {
			    if ($(this).hasClass("hasRegionList")){
				               event.stopPropagation(); //阻止事件冒泡  
				               }else{
					                   $("#RegionListInfo").hide();
				   }
				   
		});
   },
   initSourceCityList : function() {
	   Util.loadUpInfo.loadSourceCityList();
	   //Util.loadUpInfo.loadCityList();
	   Util.loadUpInfo.onclickOnbodyForCity();
		Util.loadUpInfo.onClickForCityShow();
		$("#cityListInfo li:first").click();
	},
	  initDescCityList : function() {
		   Util.loadUpInfo.loadDescCityList();
		   //Util.loadUpInfo.loadCityList();
		   Util.loadUpInfo.onclickOnbodyForCity2();
			Util.loadUpInfo.onClickForCityShow2();
			$("#cityListInfo2 li:first").click();
		},
   initCityList : function() {
	   Util.loadUpInfo.loadCityList();
	   //Util.loadUpInfo.loadCityList();
	   Util.loadUpInfo.onclickOnbodyForCity();
		Util.loadUpInfo.onClickForCityShow();
		$("#cityListInfo li:first").click();
	},
   initRegionTypleList : function() {
	   Util.loadUpInfo.loadRegionTypleList();
	   Util.loadUpInfo.onclickOnbodyForRegionTyple();
			Util.loadUpInfo.onClickForRegionTypleShow();
		},
	  initRegionList : function() {
		Util.loadUpInfo.loadRegionList();
		Util.loadUpInfo.initSearch();
		Util.loadUpInfo.onclickOnbodyForRegionList();
	},
};
